package com.windgo.controller.wx;
/**
 * @author wuwen
 * @since 2022/10/14
 * 17:47
 */

import com.windgo.bean.MarketGoods;
import com.windgo.bean.MarketUser;
import com.windgo.bean.bo.wxgoods.GoodsWxListBo;
import com.windgo.bean.bo.wxgoods.GoodsWxListVo;
import com.windgo.bean.bo.wxgoods.GoodsWxRelatedVo;
import com.windgo.bean.bo.wxgoods.WxCategoryBo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.vo.WxGoodsDetailsVo;
import com.windgo.service.CategoryService;
import com.windgo.service.GoodsService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    GoodsService goodsService;

    /**
     * 商品显示，未测试
     *
     * @param id
     * @return
     */
    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        // CommonData<MarketCategoryInfoVO> marketCategoryInfoVOCommonData = categoryService.listCategory(id);
        WxCategoryBo data = goodsService.category(id);
        return BaseRespVo.ok(data);
    }
    //http://182.92.235.201:8083/wx/goods/list?categoryId=1005002&page=1&limit=10

    /**
     * 商品显示
     *
     * @param
     * @param
     * @param
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(GoodsWxListBo goodsWxListBo, Integer id) {
        //注意
        //Subject subject = SecurityUtils.getSubject();
        // Integer id = (Integer) subject.getPrincipals().getPrimaryPrincipal();

        GoodsWxListVo goodsWxListVo = goodsService.goodsWxList(goodsWxListBo, id);
        return BaseRespVo.ok(goodsWxListVo);
    }

    /**
     * 根据id显示商品详情
     *
     * @param id
     * @return
     */
    @RequestMapping("detail")
    public BaseRespVo wxDetail(Integer id) {
        WxGoodsDetailsVo data = goodsService.wxDetail(id);
        return BaseRespVo.ok(data);

    }

    @RequestMapping("count")
    public BaseRespVo count() {
        Integer data = goodsService.countNum();
        return BaseRespVo.ok(data);
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        GoodsWxRelatedVo goodsWxRelatedVo = goodsService.goodsWxRelated(id);
        return BaseRespVo.ok(goodsWxRelatedVo);
    }

}





